import { saveAs } from "file-saver";
import axios from "axios";
import { getToken } from "@/utils/auth";
import { getNowTime } from "./date";
const baseURL = process.env.BASE_API;
export function downloadFile(name, data) {
  var url = baseURL + "/aliyun/oss/download";
  axios({
    method: "get",
    url: url,
    params: data,
    responseType: "blob",
    headers: { Authorization: getToken() }
  }).then(res => {
    console.log(res);
    const blob = new Blob([res.data]);
    saveAs(blob, name);
  });
}


export function downloadFileByUrl(name,data) {

  let str = name + '-' + getNowTime() + ".xlsx"
  const Burl = baseURL + "/company/export"
  axios({
    method: "get",
    url: Burl,
    params: data,
    responseType: "blob",
    headers: { Authorization: getToken() }
  }).then(res => {
    console.log(res);
    const blob = new Blob([res.data]);
    saveAs(blob, str);
  });

}



//导出反馈建议
export function downloadFeedback(data) {
  let str = "反馈建议-" + getNowTime() + ".xlsx"
  const Burl = baseURL + "/feedback/export"
  axios({
    method: "get",
    url: Burl,
    params: data,
    responseType: "blob",
    headers: { Authorization: getToken() }
  }).then(res => {
    const blob = new Blob([res.data]);
    saveAs(blob, str);
    console.log(res);
  })
}
